*** Clientelism as Persuasion: Evidence from Latin America ***
*** Authors: Joby Schaffer and Andy Baker ***

use "C:\Users\Andy baker\OneDrive - UCB-O365\Data\LAPOP\1626360926english_merge_2010_americasbarometer_v14v3.dta" , clear

*** Variables ***
keep if pais<40
*Create Clientelism variable (DV)
gen clientelism=1 if clien1==1
replace clientelism=1 if clien1==2
replace clientelism=0 if clien1==3

*Create Peronist Party variable
gen peronist=1 if vb11==1701
replace peronist=1 if vb11==1702
replace peronist=0 if vb11>1702
replace peronist=0 if vb11<1701

*Create Non-Peronist Party variable
gen noperonist=1 if vb11==77
replace noperonist=1 if vb11==1703
replace noperonist=1 if vb11==1704
replace noperonist=1 if vb11==1705
replace noperonist=1 if vb11==1706
replace noperonist=1 if vb11==1707
replace noperonist=0 if vb11==1701
replace noperonist=0 if vb11==1702
replace noperonist=0 if vb11>1707
replace noperonist=0 if vb11<77

*Create Radical Party variable
gen radical = 1 if vb11==1703
replace radical = 0 if vb11>1703
replace radical = 0 if vb11<1703

*Create Other Party Identifier varible
gen otherpid = 1 if vb11==77
replace otherpid = 1 if vb11==1704
replace otherpid = 1 if vb11==1705
replace otherpid = 1 if vb11==1706
replace otherpid = 1 if vb11==1707
replace otherpid = 0 if otherpid>1

*Create Party Identifier variable
gen paridentifier=vb10
recode paridentifier (1=1)(2=0)

*Create Kirchner Support variable
gen kirchner = m1 if pais==17
recode kirchner (5=1)(4=2)(3=3)(2=4)(1=5)

*Create Persuasion variable
gen persuade=pp1
recode persuade (4=0)(3=1)(2=2)(1=3)

*Create Worked for Campaign variable
gen worked=pp2
recode worked (1=1)(2=0)

*Create Involvement in a Parental Association variable
gen parent=cp7
recode parent (4=0)(3=1)(2=2)(1=3)

*Create Involvement in a Community Association variable
gen commimp=cp8
recode commimp (4=0)(3=1)(2=2)(1=3)

*Create Involvement in a Trade/Business Association variable
gen tradebiz=cp9
recode tradebiz (4=0)(3=1)(2=2)(1=3)

*Create Involvement in a Political Party Association variable
gen polparty=cp13
recode polparty (4=0)(3=1)(2=2)(1=3)

*Cronbach's alpha and factor analysis of formal association items (Argentina Only)
alpha parent commimp tradebiz polparty if pais==17, item
factor parent commimp tradebiz polparty if pais==17

*Create Association Index variable
gen association=parent+commimp+tradebiz+polparty

*Create Income variable
gen income=q10

*Create Education variable
gen education=ed

*Create Age variable
gen age=q2

*Create Gender variable
gen female=q1-1

*Create Area Size variable
tab tamano, gen(type)
rename type1 Natlcapital
rename type2 LargeCity
rename type3 MediumCity
rename type4 SmallCity
rename type5 RuralArea

*Create citysize variable for Argentina
gen citysizeARG=tamano
recode citysizeARG (5=0)(3=1)(2=2)(1=2)

*Create citysize variable for LAPOP
gen citysize=tamano
recode citysize (5=0)(4=1)(3=2)(2=3)(1=3)

*Create participation index
gen protest = prot3
recode protest (2=0)
gen townmeet = np1
recode townmeet (2=0)
gen wouldvote = vb20
recode wouldvote (1=0)(2=1)(3=1)(4=0)
gen partic = wouldvote+protest+townmeet
replace partic = protest+townmeet if pais == 8   //wouldvote not asked in this country
replace partic = protest+townmeet if pais == 13  //wouldvote not asked in this country
replace partic = protest+townmeet if pais == 22  //wouldvote not asked in this country
egen partmeans = mean(partic), by(pais)        
gen partindex = partic - partmeans               //comparable measure across countries

irt 2pl protest townmeet wouldvote  if pais==1
predict irt_part1 if pais==1, latent ebmeans
irt 2pl  protest townmeet wouldvote if pais==2, difficult intmethod(ghermite)
predict irt_part2 if pais==2, latent ebmeans
irt 2pl  protest townmeet wouldvote if pais==3
predict irt_part3 if pais==3, latent ebmeans
irt 1pl  protest townmeet wouldvote if pais==4, difficult intmethod(ghermite)
predict irt_part4 if pais==4, latent ebmeans
replace irt_part4 =-irt_part4
irt 2pl  protest townmeet wouldvote if pais==5, difficult intmethod(ghermite)
predict irt_part5 if pais==5, latent ebmeans
irt 2pl  protest townmeet wouldvote if pais==6, difficult intmethod(ghermite)
predict irt_part6 if pais==6, latent ebmeans
irt 2pl  protest townmeet wouldvote if pais==7
predict irt_part7 if pais==7, latent ebmeans
irt 1pl  protest townmeet if pais==8, difficult intmethod(ghermite)
predict irt_part8 if pais==8, latent ebmeans
irt 1pl  protest townmeet wouldvote if pais==9, difficult intmethod(ghermite)
predict irt_part9 if pais==9, latent ebmeans
irt 2pl  protest townmeet wouldvote if pais==10, difficult intmethod(ghermite)
predict irt_part10 if pais==10, latent ebmeans
irt 2pl  protest townmeet wouldvote if pais==11, difficult intmethod(ghermite)
predict irt_part11 if pais==11, latent ebmeans
irt 2pl  protest townmeet wouldvote if pais==12, difficult intmethod(ghermite)
predict irt_part12 if pais==12, latent ebmeans
irt 2pl  protest townmeet if pais==13
predict irt_part13 if pais==13, latent ebmeans
irt 2pl  protest townmeet wouldvote  if pais==14, difficult intmethod(ghermite)
predict irt_part14 if pais==14, latent ebmeans
irt 1pl  protest townmeet wouldvote  if pais==15, difficult intmethod(ghermite)
predict irt_part15 if pais==15, latent ebmeans
replace irt_part15 =-irt_part15 
irt 2pl  protest townmeet wouldvote if pais==16, difficult intmethod(ghermite)
predict irt_part16 if pais==16, latent ebmeans
irt 1pl  protest townmeet wouldvote if pais==17, difficult intmethod(ghermite)
predict irt_part17 if pais==17, latent ebmeans
irt 2pl protest townmeet wouldvote if pais==21, difficult intmethod(ghermite)
predict irt_part21 if pais==21, latent ebmeans
irt 1pl  protest  townmeet if pais==22, difficult intmethod(ghermite)
predict irt_part22 if pais==22, latent ebmeans
irt 1pl  protest  townmeet wouldvote if pais==23, difficult intmethod(ghermite)
predict irt_part23 if pais==23, latent ebmeans
irt 1pl  protest  townmeet wouldvote if pais==24, difficult intmethod(ghermite)
predict irt_part24 if pais==24, latent ebmeans
irt 2pl  protest  townmeet wouldvote if pais==25
predict irt_part25 if pais==25, latent ebmeans
irt 2pl  protest  townmeet wouldvote if pais==26, difficult intmethod(ghermite)
predict irt_part26 if pais==26, latent ebmeans
irt 1pl  protest  townmeet wouldvote if pais==27, difficult intmethod(ghermite)
predict irt_part27 if pais==27, latent ebmeans
replace irt_part27 =-irt_part27
egen irt_part=rowmax(irt_part*)

*Awareness
recode gi3 gi4 gi1 (2=0)
recode pol1 4=1 2=3 3=2 1=4
recode m1 .=0 else=1, gen(m1op)
recode m2 .=0 else=1, gen(m2op)
recode l1 .=0 else=1, gen(m3op)
recode b11 .=0 else=1, gen(m4op)
gen m=m1op+m2op+m3op+m4op

irt grm gi3 gi4 gi1 m pol1  if pais==1
predict irt_know1 if pais==1, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1  if pais==2
predict irt_know2 if pais==2, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1  if pais==3
predict irt_know3 if pais==3, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1  if pais==4
predict irt_know4 if pais==4, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1  if pais==5
predict irt_know5 if pais==5, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1  if pais==6, difficult intmethod(ghermite)
predict irt_know6 if pais==6, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1  if pais==7
predict irt_know7 if pais==7, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1  if pais==8
predict irt_know8 if pais==8, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1  if pais==9
predict irt_know9 if pais==9, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1  if pais==10, difficult intmethod(ghermite)
predict irt_know10 if pais==10, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1  if pais==11
predict irt_know11 if pais==11, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1  if pais==12, difficult intmethod(ghermite)
predict irt_know12 if pais==12, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1 if pais==13
predict irt_know13 if pais==13, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1 if pais==14, difficult intmethod(ghermite)
predict irt_know14 if pais==14, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1 if pais==15
predict irt_know15 if pais==15, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1 if pais==16
predict irt_know16 if pais==16, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1 if pais==17
predict irt_know17 if pais==17, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1 if pais==21, difficult intmethod(ghermite)
predict irt_know21 if pais==21, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1 if pais==22, difficult intmethod(ghermite)
predict irt_know22 if pais==22, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1 if pais==23
predict irt_know23 if pais==23, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1 if pais==24
predict irt_know24 if pais==24, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1 if pais==25
predict irt_know25 if pais==25, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1 if pais==26, difficult intmethod(ghermite)
predict irt_know26 if pais==26, latent ebmeans
irt grm  gi3 gi4 gi1 m pol1 if pais==27
predict irt_know27 if pais==27, latent ebmeans

egen irt_know=rowmax(irt_know*)


*** Descriptive Statistics ***

*Summarize each variable
foreach x of varlist clientelism-partindex {
	summarize `x', detail
}

*Level of clientelism across each country
forval i = 1/27 {
	tab clientelism if pais == `i'
}

*Polychoric correlations between persuasion frequency and partisan identifier in LAPOP and individual countries
polychoric persuade paridentifier
estimates store LAPOP
forval i = 1/17 {
	polychoric persuade paridentifier if pais==`i'
	estimates store country`i'
}
forval i = 21/26 {
	polychoric persuade paridentifier if pais==`i'
	estimates store country`i'
}	
estimates table LAPOP country*
estimates clear

*Correlation table 
corr persuade kirchner parent commimp tradebiz polparty worked partic partindex income education age protest townmeet wouldvote citysize

*Barplot of persuasion levels for clients and non-clients
gen client_rev = 0 if clientelism==1
replace client_rev = 1 if clientelism==0
label define x 0 "Targets" 1 "Non-targets"
label values client_rev x
gen persuade0 = 1 if persuade==0
replace persuade0 = 0 if persuade==1 | persuade==2 | persuade==3
gen persuade1 = 1 if persuade==1
replace persuade1 = 0 if persuade==0 | persuade==2 | persuade==3
gen persuade2 = 1 if persuade==2
replace persuade2 = 0 if persuade==1 | persuade==0 | persuade==3
gen persuade3 = 1 if persuade==3
replace persuade3 = 0 if persuade==1 | persuade==2 | persuade==0

graph bar (mean) persuade0 persuade1  persuade2 persuade3 if pais==17, over(client_rev) stack percent  ///
graphregion(color(white) margin(medlarge)) plotregion(lstyle(yxline) lcolor(black))  ///
ytitle("{bf:Percentage (cumulative) of Respondents}")  legend(pos(3) cols(1) order(4 "Frequently" 3 "Occasionally" 2 "Rarely" 1 "Never")) ylab(0 "0" 20 ".2" 40 ".4" 60 ".6" 80 ".8" 100 "1") ///
bar(1, color(black)) bar(2, color(gs6)) bar(3, color(gs10)) bar(4, color(gs14)) ylab(0 "0%" .2 "20%" .4 "40%" .6 "60%" .8 "80%" 1 "100%")

*Figure 7.2
graph bar (mean) persuade0 persuade1  persuade2 persuade3 [pweight=weight1500], over(client_rev) stack percent  ///
graphregion(color(white) margin(medlarge)) plotregion(lstyle(yxline) lcolor(black)) ///
ytitle("{bf:Percentage (cumulative) of Respondents}")  legend(off) ///
bar(1, color(black)) bar(2, color(gs6)) bar(3, color(gs10)) bar(4, color(gs14)) ylab(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%") ///
text(23.93 23.25 "Never", color(white)) text(56.96 23 "Rarely", color(white)) text(76.92 23 "Occasionally", color(white)) text(93.88 23 "Frequently", color(black)) ///
text(36.78 77.25 "Never", color(white)) text(79.55 77.25 "Rarely", color(white)) text(90.155 77.25 "Occasionally", color(white)) text(97.37 77.25 "Frequently", color(black))

*legend(pos(3) cols(1) order(4 "Frequently" 3 "Occasionally" 2 "Rarely" 1 "Never"))
graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Chapter 7 Clientelism\Figures\Bar Graph LatAm.tif", as(tif) replace
graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Publishers\Final Manuscript\Final Figures\BAR7_2.tif", as(tif) replace width(1500)
graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Publishers\Final Manuscript\Final Figures\BAR7_2.pdf", as(pdf) replace 


quietly logit clientelism persuade paridentifier irt_part  i.pais [pw=weight1500], cluster(pais)
gen esample=e(sample)

*Figure 7.3, Table A.19
//Model 1
eststo: logit clientelism paridentifier irt_part i.pais if esample==1 [pw=weight1500], cluster(pais)
//Model 2
eststo: logit clientelism persuade paridentifier irt_part i.pais [pw=weight1500], cluster(pais)
margins, at(persuade==3 (means)_all) 
margins, at(persuade==0 (means)_all) 

label variable paridentifier "Partisan identifier"
label variable persuade "Persuasion frequency"
label variable irt_part "Political participation index"

coefplot (est1, label(Model 1) mcolor(black) ciopts(lcolor(black) recast(rcap)))  ///
(est2, label(Model 2) mcolor(black) msymbol(S) ciopts(lcolor(black) recast(rcap))) , ///
drop(*.* _cons) xline(0, lcolor(black)) yline(1.5 2.5 , lcolor(gs8)) ///
legend(cols(1)) graphregion(color(white)) order(paridentifier irt_part persuade ) plotregion(lstyle(yxline) lcolor(black)) ///
coeflabel(,wrap(32)) msize(small) ///
xtitle("{bf:Logit Coefficient}") ytitle("{bf:Independent Variables}") ///
title("{bf:Dependent Variable: Target of Clientelism}", size(medsmall) color(black)) 
graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Chapter 7 Clientelism\Figures\Lapop2010CoefPlot.tif", as(tif) replace
graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Publishers\Final Manuscript\Final Figures\BAR7_3.tif", as(tif) replace width(1500)
graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Publishers\Final Manuscript\Final Figures\BAR7_3.pdf", as(pdf) replace 

*Table A.19, mentioned in text around 7.3
//Model 3
eststo: logit clientelism irt_know i.pais if esample==1 [pw=weight1500], cluster(pais)
margins, at(irt_know==1.661095 (means)_all) 
margins, at(irt_know==-2.821867 (means)_all) 
//Model 4
eststo: logit clientelism persuade irt_know i.pais if esample==1 [pw=weight1500], cluster(pais)
xyz
cd "C:\Users\Andy Baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Chapter 7 Clientelism\Code\Output\"
esttab est1 est2 est3 est4 using LatAm_models.rtf, label b(3) replace se star(* 0.05 ) nogap onecell title(Table A.19: Clientelistic Targeting by Persuasion Frequency: Results from 22 Latin American Countries, 2010) ///
modelwidth(6) nonumbers mtitles("1" "2" "3" "4") compress

*Table 7.1
eststo clear
//Model 1: Brazil
eststo: logit clientelism paridentifier irt_part if esample==1 & pais==15
//Model 2: Brazil
eststo: logit clientelism persuade paridentifier irt_part if esample==1 & pais==15
//Model 3: Mex
eststo: logit clientelism paridentifier irt_part if esample==1 & pais==1
//Model 4: Mex
eststo: logit clientelism persuade paridentifier irt_part if esample==1 & pais==1
//Model 5: Arg
eststo: logit clientelism paridentifier irt_part if esample==1 & pais==17
//Model 6: Arg
eststo: logit clientelism persuade paridentifier irt_part if esample==1 & pais==17

cd "C:\Users\Andy Baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Chapter 7 Clientelism\Code\Output\"
esttab est1 est2 est3 est4 est5 est6 using country_models.rtf, label b(3) replace se star(* 0.05 ) nogap onecell title(Table 7.1: Clientelistic Targeting by Persuasion Frequency in Brazil, Mexico, Argentina) ///
modelwidth(6) nonumbers mtitles("1" "2" "3" "4" "5" "6") compress


